import { createStore } from 'vuex'
import { getMusicLyric } from '@/request/api/item'
import { createLogin } from '@/request/api/home'
export default createStore({
  state: {
    playList: [{
      al: {
        id: 2646285,
        name: "安和桥北",
        pic: 109951163200249250,
        picUrl: "https://p2.music.126.net/GcRunGm02vZBicYmIN6GXw==/109951163200249252.jpg",
        pic_str: "109951163200249252",
      },
      ar: [{ name: "宋冬野" }],
      name: '安河桥北',
      id: 27646205,
    }],
    playListIndex: 0,
    isBtnShow: true,
    detailShow: false,
    LyricList: [],
    currentTime: 0,
    duration: 0,
    isLogin: false,
    isFooterMusic: true,
    account: {}
  },
  getters: {
  },
  mutations: {
    updateIsBtnShow (state, value) {
      state.isBtnShow = value
    },
    updatePlayList (state, value) {
      state.playList = value
      console.log(state.playList)
    },
    pushPlayList (state, value) {
      state.playList.push(value)
    },
    updatePlayListIndex (state, value) {
      state.playListIndex = value
    },
    updateDetailShow (state) {
      state.detailShow = !state.detailShow
    },
    updateLyricList (state, value) {
      state.LyricList = value
    },
    updateCurrentTime (state, value) {
      state.currentTime = value * 1000
    },
    updateDuration (state, value) {
      state.duration = value * 1000
    },
    updateAccount (state, value) {
      state.account = value
      console.log(state.account)
    },
    updateIsLogin (state, value) {
      state.isLogin = value
    },
  },
  actions: {
    async getLyric (context, value) {
      const { data: res } = await getMusicLyric(value)
      context.commit('updateLyricList', res.lrc.lyric)
    },
    async getLoginBase (context, value) {
      const { data: res } = await createLogin(value)
      context.commit('updateLoginBase', res.data.qrimg)
    },
    async getLoginAccount (context) {
      const { data: res } = await getLoginMessage()
      context.commit('updateAccount', res)
    },
  },
  modules: {
  }
})
